<template>
  <div class="video-container">
    <!-- 视频元素 -->
    <div v-if="videoSrc" class="video-player-wrapper">
      <video
          :src="videoSrc"
          controls
          class="video-player"
          @play="onPlay"
          @pause="onPause"
          @ended="onEnded">
      </video>
      <div v-if="!isPlaying" class="overlay">
        <button class="play-btn" @click="togglePlay">
          <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <polygon points="5 3 19 12 5 21 5 3"></polygon>
          </svg>
        </button>
      </div>
    </div>
    <button v-else class="load-video-btn" @click="loadVideo">加载宣传视频</button>
  </div>
</template>

<script>
export default {
  name: 'PromotionalVideo',
  data() {
    return {
      videoSrc: '', // 视频源地址
      isPlaying: false, // 视频是否正在播放
    };
  },
  methods: {
    loadVideo() {
      // 设置视频源地址
      this.videoSrc = '你的宣传视频链接.mp4'; // 替换为实际的视频链接
    },
    togglePlay() {
      const video = this.$el.querySelector('video');
      if (this.isPlaying) {
        video.pause();
      } else {
        video.play();
      }
    },
    onPlay() {
      this.isPlaying = true;
    },
    onPause() {
      this.isPlaying = false;
    },
    onEnded() {
      this.isPlaying = false;
    }
  }
};
</script>

<style scoped>
.video-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.video-player-wrapper {
  position: relative;
  width: 100%;
  max-width: 800px;
  border-radius: 15px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1), 0 6px 6px rgba(0, 0, 0, 0.1);
  background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
}

.video-player {
  width: 100%;
  height: auto;
  border: none;
  outline: none;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: background 0.3s ease;
}

.play-btn {
  background: rgba(255, 255, 255, 0.8);
  border: none;
  border-radius: 50%;
  padding: 15px;
  cursor: pointer;
  transition: background 0.3s ease;
}

.play-btn:hover {
  background: rgba(255, 255, 255, 0.9);
}

.load-video-btn {
  padding: 15px 30px;
  font-size: 18px;
  color: white;
  background: linear-gradient(135deg, #f6d365 0%, #fda085 100%);
  border: none;
  border-radius: 30px;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
}

.load-video-btn:hover {
  transform: translateY(-3px);
}
</style>